exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseSocket {
  /**
     * 查询全部事件分类
     */
  getAllEventGroupAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const EventService = _this.service('api/cms/EventService');
      const res = yield EventService.getAllEventGroup();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '数据库查询错误';
      }
      return _this.json(aj);
    })();
  }

  /**
     * 保存图片
     */
  doUploadImgAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const file = _this2.file('image');
      const aj = think.ajaxJson();
      const serverIP = 'http://' + think.config('staticIp') + ':' + think.config('proxyPort');

      if (file) {
        // 保存图片
        const pathObj = yield _this2.renameFile(file);
        if (pathObj) {
          aj.success = true;
          aj.msg = '上传成功';
          aj.result = {
            fileName: pathObj.filePathStatic,
            filePathStatic: serverIP + '/' + pathObj.filePathStatic
          };
        } else {
          aj.success = false;
          aj.msg = '图片保存失败';
        }
      } else {
        aj.success = false;
        aj.msg = '文件上传失败';
      }
      return _this2.json(aj);
    })();
  }

  /**
     * 查询事件列表
     */
  getEventListAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      let CHECK = _this3.post('is_check');
      console.log('52', CHECK);
      if (!_this3.post('is_check')) {
        CHECK = '0,1,2';
      }
      const data = {
        page: Number(_this3.post('page')),
        pageSize: Number(_this3.post('pageSize')),
        userId: _this3.post('userId'),
        flag: Number(_this3.post('flag')),
        group_code: _this3.post('group_code'),
        area_code: _this3.post('area_code'),
        is_check: CHECK.split(',')
      };
      const EventService = _this3.service('api/cms/EventService');
      const res = yield EventService.getEventListBy(data);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '数据库查询错误';
      }
      return _this3.json(aj);
    })();
  }

  /**
     * 事件上报接口
     */
  addEventAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      return _this4.action('cms/EventController', 'allEventReport');
      // let data = this.post('objName,ObjPosition,BGID,area_code,remarks');
      // data.baidu_x = Number(this.post('baidu_x'));
      // data.baidu_y = Number(this.post('baidu_y'));
      // data.source = Number(this.post('source'));
      // if (this.post('businesskey') && this.post('businesskey') !== '') {
      //     data.businesskey = this.post('businesskey');
      // }
      // if(this.post('group_code')&&this.post('area_code')){//传分类编码和区域
      //     data.parent_name = this.post('parent_name');
      //     data.sub_name = this.post('sub_name');
      //     data.group_code = this.post('group_code');
      //     data.type = Number(this.post('type'));
      //     data.ObjCode = this.post('area_code') + this.post('group_code');
      // }
      // if (this.post('userId')) {
      //     data.create_by = this.post('userId');
      //     data.create_date = new Date();
      //     data.update_date = data.create_date;
      //     data.update_by = data.create_by;
      //     if (this.post('img_push') && this.post('img_push').length > 0) {
      //         data.pic_path = this.post('img_push').split(',');
      //     }
      //     const EventService = this.service('api/cms/EventService');
      //     let res = await EventService.addEvent(data);
      //     if (res && res.error) {
      //         return this.errorJson('查询失败')
      //     }
      //
      //     const userIds = await this.getOnlineModuleByUser('jdsl');
      //     let obj = this.getSocketMsgBody(res);
      //
      //     //推给所有受理中心人员
      //     this.sendMsgByUserAction(obj, userIds, 'accept_screen');
      //     // this.sendMsgByUserAction(obj, userIds, 'control_center');
      //
      //     // const user_id = await this.getOnlineModuleByUser();
      //     //就事件随机推送给某个用户
      //     // const randomId = userIds[Math.floor(Math.random() * userIds.length)];
      //
      //     // console.log(randomId, 'randomId');
      //     // let obj = this.getSocketMsgBody(result);
      //     // let socketBody = {
      //     //     result: {
      //     //         title: '新的事件上报',
      //     //         date: new Date()
      //     //     },
      //     //     moduleName: 'jdsl',
      //     //
      //     //     menuUrl: 'accept'
      //     // };
      //     // this.sendMsgByUserAction(socketBody, user_id, 'msg_box');
      //
      //     return this.successJson();
      //
      // } else {
      //     return this.errorJson('用户id不能为空')
      // }
      //     //上报成功推送到web端
    })();
  }

  /**
     * 修改事件接口
     */
  editEventAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = _this5.post('id,objName,ObjPosition,source,parent_name,sub_name,area_code,group_code,remarks');
      if (_this5.post('userId')) {
        data.type = Number(_this5.post('type'));
        data.update_by = _this5.post('userId');
        data.update_date = new Date();
        data.ObjCode = _this5.post('area_code') + _this5.post('group_code');
        if (_this5.post('img_push') && _this5.post('img_push').length > 0) {
          data.pic_path = _this5.post('img_push').split(',');
        }
        const EventService = _this5.service('api/cms/EventService');
        const res = yield EventService.editEvent(data);
        if (res && (res.error || res.msg)) {
          aj.success = false;
          aj.msg = '数据库查询错误';
        }
      } else {
        aj.success = false;
        aj.msg = '未接收到用户信息';
      }

      return _this5.json(aj);
    })();
  }

  /**
     * 删除事件
     */
  delEventAction() {
    var _this6 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = {
        id: _this6.post('eventId')
      };
      const EventService = _this6.service('api/cms/EventService');
      const res = yield EventService.delEvent(data);
      if (res.error) {
        aj.msg = '撤回事件失败';
        aj.success = false;
      }
      return _this6.json(aj);
    })();
  }

  /**
     * 核实事件
     */
  checkEventAction() {
    var _this7 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      // let DATA = this.wsData;
      const DATA = _this7.post();
      const data = {
        id: _this7.post('eventId'),
        is_check: Number(_this7.post('is_check')),
        verify_date: new Date(),
        verify_remark: _this7.post('verify_remark'),
        status: 3
      };
      if (data.is_check === 2) {
        // 不通过
        data.status = 6; // 待立案
      }
      const EventService = _this7.service('api/cms/EventService');
      const res = yield EventService.checkEvent(data);
      const result = yield EventService.checkEventDetail(data);
      if (res.error) {
        aj.msg = '事件核实失败';
        aj.success = false;
      }
      const randomId = _this7.post('update_by');
      const obj = _this7.getSocketMsgBody(result);
      _this7.sendMsgByUserAction(obj, [randomId], 'accept_screen');

      // let socketBody = {
      //     result: {
      //         title: '新的事件核实',
      //         id: data.id,
      //         date: new Date()
      //     },
      //     moduleName: 'jdsl',
      //
      //     menuUrl: 'accept'
      // };
      // this.sendMsgByUserAction(socketBody, [randomId], 'msg_box');
      return _this7.successJson();
    })();
  }

  /**
     * 根据事件id获取事件详情
     */
  getEventInfoAction() {
    var _this8 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      let res = {};
      const data = {
        id: _this8.post('eventId')
      };
      const EventService = _this8.service('api/cms/EventService');
      if (_this8.post('flag')) {
        // 微信用户上报
        res = yield EventService.getWechatEventInfo(data);
      } else {
        res = yield EventService.getEventInfo(data);
      }
      if (!res.error) {
        aj.result = res;
      } else {
        aj.msg = '事件详情获取失败或已被删除';
        aj.success = false;
      }
      return _this8.json(aj);
    })();
  }

  /**
     * 获取事件核实状态列表
     */
  verifyStateListAction() {
    var _this9 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const EventService = _this9.service('api/cms/EventService');
      const res = yield EventService.verifyStateList();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.msg = '事件核实状态列表获取失败';
        aj.success = false;
      }
      return _this9.json(aj);
    })();
  }
};